<template>
  <div class="notfound">
    <svg-icon name="404" class="icon" />
    <div class="content">
      <h1>404</h1>
      <div class="desc">抱歉，你访问的页面不存在</div>
      <el-button type="primary" @click="goBack">{{ data.countdown }} 秒后，返回首页</el-button>
    </div>
  </div>
</template>
<script lang="ts" setup>
import SvgIcon from '@/components/SvgIcon/index.vue'
import { onBeforeRouteLeave } from 'vue-router'
import { onMounted, ref } from 'vue'
import { _window } from '../src/global.ts'

const data = ref<{
  inter: NodeJS.Timeout | null
  countdown: number
}>({
  inter: null,
  countdown: 5,
})

onBeforeRouteLeave(() => {
  clearInterval(data.value.inter!)
})

onMounted(() => {
  data.value.inter = setInterval(() => {
    data.value.countdown--
    if (data.value.countdown === 0) {
      clearInterval(data.value.inter!)
      goBack()
    }
  }, 1000)
})

function goBack() {
  _window.router.push({
    name: 'test',
  })
}
</script>
<style lang="scss" scoped>
.notfound {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 700px;
  @include position-center(xy);
  .icon {
    width: 400px;
    height: 400px;
  }
  .content {
    h1 {
      margin: 0;
      font-size: 72px;
      color: var(--ml-text-color-primary);
    }
    .desc {
      margin: 20px 0 30px;
      font-size: 20px;
      color: var(--ml-text-color-secondary);
    }
  }
}
</style>
